"""
给定一组数据网址数据，请判断这些网址是否可以访问； 用多线程的方式来实现；
请查资料，Python的 requests库，如何判断一个网址可以访问；
"""
import requests
from concurrent.futures import ThreadPoolExecutor


headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}

def func(url):
    try:
        res = requests.get(url, headers=headers)
        code = res.status_code
        if code == 200:
            print(url, "ok")
        else:
            print(url,'fail')
    except:
        pass


if __name__ == '__main__':
    with open('url_data.txt', mode='r', encoding='gbk') as f:
        url_list = f.read().strip().split('\n')

    with ThreadPoolExecutor(10) as t:
        for url in url_list:
            t.submit(func, url)


